﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpBolt.Graphics.GraphicSources;
using SharpBolt.Basics;
using System.ComponentModel;
using Newtonsoft.Json;

namespace SharpBolt.Graphics.GraphicInstances
{
    [TypeConverter(typeof(ExpandableObjectConverter))]
    [JsonObject]
    public class ImageInstance : GraphicInstance
    {
        [JsonIgnore]
        public ImageSource ImageSource
        {
            get
            {
                return Source as ImageSource;
            }
            set
            {
                Source = value;
            }
        }

        [JsonIgnore]
        public SbBitmap CurrentBitmap { get { return ImageSource.Bitmap; } }

        public ImageInstance(ImageSource source)
            : base()
        {
            Source = source;
        }

        public override void Draw(Painter painter)
        {
            if (Hidden) return;

            var trans = Transformation.Copy();
            trans.Position += HotSpot * trans.Scale;
            trans.Shift -= HotSpot * trans.Scale;

            Source.Draw(painter, trans, Color);
        }

        public override InductBase.Vec2 Size
        {
            get
            {
                return ImageSource.Bitmap.Size;
            }
        }
    }
}
